<?php htmlTemplate('admin_header_frame.php');?>
<script type="text/javascript">
function setThumbImg(src){
	$("#thumb").val(src);
}
function checkForm()
{
	var columns = $.trim($("#columns").val());
	var title = $.trim($("#title").val());
	var content = $.trim(KE.util.getData('content'));
	var source =  $.trim($("#source").val());
	var author =  $.trim($("#author").val());
	var createby =  $.trim($("#createby").val());
	var tags =  $.trim($("#tags").val());
	var description =  $.trim($("#description").val());
	var thumb =  $.trim($("#thumb").val());	var swf =  $.trim($("#swf").val());
	var ralation =  $.trim($("#ralation").val());
	var allowcomment = $("#allowcomment").attr("checked");

	if (columns==0){	
		parent.showAlert('请选择栏目！');	
		return false;	
	}
	if (title==''){	
		parent.showAlert('新闻名称不能为空！');	
		return false;	
	}
	if (title==''){	
		parent.showAlert('新闻名称不能为空！');	
		return false;	
	}
	if(content==''){
		parent.showAlert('内容不能为空！');
		return false;
	}

	<?php 
	if ($news){
		$url = MVC_WWW_HOST.'admin/news/modify/do/update/id/'.$news['id'];
	}else{
		$url = MVC_WWW_HOST.'admin/news/add/do/add';
	}
	?>
	var url = '<?php echo $url;?>';
	$("#submitnews").attr({"disabled":"disabled"});
	$.post(url,{'title':title,'columns':columns,'content':content,'swf':swf,
		'source':source,'author':author,'createby':createby,
		'tags':tags,'description':description,'thumb':thumb,'ralation':ralation,'allowcomment':allowcomment},function(rs){
		
		if(rs>0){
			parent.showAlert('保存成功！')
			$("#submitnews").attr({"disabled":""});
		}else{
			$("#submitnews").attr({"disabled":""});
			
		}
	});
	return false;
}

</script>
<form method="post" action="<?php echo MVC_WWW_HOST ?>/admin/news/add/do/add" onsubmit="return checkForm()">
<table style="line-height: 30px;">
	<tr>
		<td align="right">栏 目： </td>
		<td><select name="columns" id="columns">
			<?php if($news){?>
			<option value="<?php echo $news['columns']?>"><?php echo $news['cname']?></option>
			<?php }else{
				echo '<option value="0">请选择栏目</option>';
			}?>
			<?php foreach ($columns as $key=>$value):?>
			<option value="<?php echo $value['id']?>"><?php echo $value['cname']?></option>
				<?php 
				if(@$value['child']){
					foreach ($value['child'] as $k=>$v):?>
					<option value="<?php echo $v['id']?>">|----<?php echo $v['cname']?></option>
					<?php endforeach;
				}?>
			<?php endforeach;?>
		</select></td>
	</tr>    		
	<tr>
		<td align="right">名 称： </td>
		<td><input type="text" style="width:300px;" id="title" name="title" value="<?php if($news) echo $news['title'];?>"></td>
	</tr>
	<tr>
		<td  align="right">来 源：</td>
		<td><input type="text" name="source" id="source" value="<?php if($news) echo $news['source'];?>">&nbsp;&nbsp;
		作 者：<input type="text" name="author" id="author" value="<?php if($news) echo $news['author'];?>">&nbsp;&nbsp;
		编 辑：<input type="text" name="createby" id="createby" value="<?php if($news) {echo $news['createby'];}else{ echo $user['username'];}?>"></td>
	</tr>
	<tr>
		<td valign="top" align="right">tags：</td>
		<td><input type="text" style="width:300px;" name="tags" id="tags" value="<?php if($news) echo $news['tags'];?>"> &nbsp;&nbsp;多个tags之间字用分号（;）分开</td>
	</tr>
	<tr>
		<td valign="top" align="right">摘 要：</td>
		<td><textarea style="width:798px;height:50px;" id="description" name="description"><?php if($news) echo $news['description'];?></textarea></td>
	</tr>    <tr>		<td valign="top" align="right">视频地址：</td>		<td><input type="text" style="width:300px;" name="swf" id="swf" value="<?php if($news) echo $news['swf'];?>"> &nbsp;&nbsp;</td>	</tr>	<?php 	echoEditTr($news,'缩略图：','thumb',400,'thumb');	?>	
	<tr>
		<td align="right"></td>
		<td   style="padding-top:10px;" ><?php 
		if ($news){
			$content = $news['content'];			
		}else{
			$content=null;
		}
		
		echo editor('content',800,300,$content);
		?></td>
	</tr>
	<tr>
		<td valign="top" align="right">相关文章：</td>
		<td>
		<script type="text/javascript">
		function search_relation()
		{
			var url = '<?php echo MVC_WWW_HOST.'admin/api/relation'?>';
			showFrame(url,800,434); 
		}
		function setRes(rs){
			$("#ralation").val(rs);
		}
		</script>
		<input type="text" readonly="readonly" style="width:350px;" id="ralation" name="ralation"  value="<?php if($news) echo $news['ralation'];?>"> <input type="button" value="搜 索" onclick="search_relation()"></td>
	</tr>
	<tr>
		<td valign="top" align="right">允许评论：</td>
		<td><input type="checkbox" name="allowcomment" id="allowcomment" 
		<?php 
		if ($news){ 
			if ($news['allowcomment']){
				echo 'checked="checked"';
			}
		}?>></td>
	</tr>
	<tr>
		<td align="right"></td>
		<td style="padding-top:10px;"><input id="submitnews" type="submit" value="提 交"  class="submit" /></td>
	</tr>
</table>
</form><script type="text/javascript">function cutimg(thumbid){	 	if (!thumbid){		thumbid='thumb';	}	var img = $.trim($("#"+thumbid).val());	if (img ==''){		parent.showAlert('请先上传图片！');		return false;	}	var url = '<?php echo MVC_WWW_HOST.'admin/api/cutimg?imgsrc='?>'+img+'&thumbid='+thumbid;	showFrame(url,500,450);}function showSysimg(thumbid){	if (!thumbid){		thumbid='thumb';	}	 	var url = '<?php echo MVC_WWW_HOST.'admin/api/sysimg';?>'+'/thumbid/'+thumbid;	showFrame(url,700,450);}</script>